package com.carefree.common.core;

import com.carefree.common.emus.StatusCodeEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * @ClassName:Result
 * @Description:
 * @Author Tengbin tengbin234@163.com
 */
@Data
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 响应码
     */
    private int code;

    /**
     * 响应消息
     */
    private String msg;

    /**
     * 响应数据
     */
    private T data;

    public Result() {
    }

    private Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> ok() {
        return new Result(StatusCodeEnum.SUCCESS.getCode(), StatusCodeEnum.SUCCESS.getMessage(), (Object) null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(StatusCodeEnum.SUCCESS.getCode(), StatusCodeEnum.SUCCESS.getMessage(), data);
    }

    public static <T> Result<T> success(String msg, T data) {
        return new Result<>(StatusCodeEnum.SUCCESS.getCode(), msg, data);
    }

    public static <T> Result<T> success(int code, String msg, T data) {
        return new Result<>(code, msg, data);
    }

    public static <T> Result<T> error() {
        return new Result(StatusCodeEnum.FAUIL.getCode(), StatusCodeEnum.FAUIL.getMessage(), (Object) null);
    }

    public static <T> Result<T> error(String msg) {
        return new Result(StatusCodeEnum.FAUIL.getCode(), msg, (Object) null);
    }

    public static <T> Result<T> error(int code, String msg) {
        return new Result(code, msg, (Object) null);
    }

    public int getCode() {
        return this.code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
